package com.fcx.workai.loginmodule.ui.setpwd;


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.hxh.component.basicore.component.mvp.view.BaseFragment;

import com.fcx.workai.loginmodule.R;
import com.fcx.workai.loginmodule.bean.UserSetPwdResultBean;



/**
 * 创建者：hxh
 * 时间：  2017/8/4
 * 描述：
 */
public class SetPwdFragment extends BaseFragment<SetPwdPresenter> implements SetPwdContract.V {

    private EditText et_realpwd, et_pwd;
    private Button btn_next;
    private String mCurrentVerityCode;

    public static SetPwdFragment newInstance() {

        Bundle args = new Bundle();
        SetPwdFragment fragment = new SetPwdFragment();

        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_setpwd;
    }

    @Override
    public void initData(Bundle saveInstanceState) {
        initView();
    }

    private void initView() {

        et_realpwd = findViewBy(R.id.et_realpwd);
        et_pwd = findViewBy(R.id.et_pwd);
        btn_next = findViewBy(R.id.btn_next);
        btn_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                request_setPwd();
            }
        });
    }

    private void request_setPwd() {
        if (!isEmpty(et_pwd) && !isEmpty(et_realpwd)) {
            if (et_pwd.getText().length() > 7 && et_realpwd.getText().length() > 7) {
                if (getText(et_realpwd).equals(getText(et_pwd))) {
                    getP().setPwd(getText(et_realpwd));
                } else {
                    toastShort("两次密码不一致！");
                }
            } else {
                toastShort("密码长度必须大于7位！");
            }
        }
    }

    @Override
    public SetPwdPresenter newP() {
        return new SetPwdPresenter();
    }

    @Override
    public void showLoginResule(UserSetPwdResultBean resule) {
       // toastShort("密码设置成功 " + resule);
        getActivity().finish();
    }
}
